import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import eslintPlugin from 'vite-plugin-eslint'
// 配置自动加载elemnt-plus组件
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
    server: {
        host: '0.0.0.0', // 设置后同一个服务器下的设备可以通过访问Network中的ip来访问项目
        port: 80, // 自定义端口
        open: false // 设置服务启动时是否自动打开浏览器
    },
    resolve: {
        alias: {
            '@': resolve(__dirname, 'src')
        }
    },
    plugins: [
        vue(),
        eslintPlugin({
            include: ['src/**/*.ts', 'src/**/*.vue', 'src/*.ts', 'src/*.vue']
        }),
        AutoImport({
            resolvers: [ElementPlusResolver()]
        }),
        Components({
            // 自动引入组件的路劲
            dirs: ['src/components'],
            extensions: ['vue', 'md'],
            include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
            resolvers: [
                ElementPlusResolver({
                    importStyle: 'sass'
                })
            ],
            // 导出的文件名称
            dts: 'components.d.ts'
        })
    ]
})
